package com.tiankong.product.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.tiankong.product.entity.CategoryBrand;
import com.tiankong.product.mapper.CategoryBrandMapper;
import com.tiankong.product.service.CategoryBrandRelationService;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * <p>
 * 品牌分类关联 服务实现类
 * </p>
 *
 * @author scl
 * @since 2021-03-22
 */
@Service
public class CategoryBrandRelationServiceImpl extends ServiceImpl<CategoryBrandMapper, CategoryBrand> implements CategoryBrandRelationService {
    @Override
    public void saveRelation(CategoryBrand categoryBrand) {
        CategoryBrand relation = query().eq("brand_id", categoryBrand.getBrandId()).eq("catelog_id", categoryBrand.getCatelogId()).one();
        if (relation == null){
            save(categoryBrand);
        }
    }

    @Override
    public List<CategoryBrand> listByBrandId(Long brandId) {
        return getBaseMapper().selectListByBrandId(brandId);
    }

    @Override
    public List<CategoryBrand> listBrandByCatId(Long catId) {
        return getBaseMapper().selectBrandsByCatId(catId);
    }
}
